package com.hm.ibsm.web.mg;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hm.ibsm.auto.helper.SystemSessionHolder;
import com.hm.ibsm.def.enums.DictTypeEnums;
import com.hm.ibsm.service.DictService;
import com.hm.ibsm.util.BaseController;

import lombok.extern.slf4j.Slf4j;

/**
 * @author shishun.wang
 * @date 2017年3月24日 下午6:12:08
 * @version 1.0
 * @describe
 */
@Slf4j
@Controller
@RequestMapping("/mg/dict")
public class DictController extends BaseController {

	private String MODEL_NAME = DictController.class.getName();

	@Autowired
	private DictService dictService;

	@RequestMapping(value = "/index.do", method = RequestMethod.GET)
	public ModelAndView dictMg() {
		try {
			Map<String, Object> mapper = new HashMap<String, Object>();
			{
				mapper.put("dictTypes", DictTypeEnums.load());
			}

			return new ModelAndView("mg/dict", mapper);
		} catch (Exception e) {
			log.error(MODEL_NAME, e);
			return sessionTimeOut();
		}
	}

	@RequestMapping(value = "/query.do", method = RequestMethod.GET)
	public @ResponseBody String query(@RequestParam(name = "dictType", required = false) DictTypeEnums dictType, @RequestParam(name = "code", required = false) String code) {
		return json(dictService.query(SystemSessionHolder.pageParam(), dictType, code)).toString();
	}
}
